﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.DataObject;
using System.Data;
using System.Data.SqlClient;

namespace DataAccess.BusinessObject
{
    public class BOrderDetails:Common.CDBase
    {
        public bool Add(OOrderDetails _OOrderDetails)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDOrder",SqlDbType.Int)
                                      , new SqlParameter("@IDProduct",SqlDbType.Int)
                                      , new SqlParameter("@TotalQuantity",SqlDbType.Decimal)
                                      , new SqlParameter("@TotalPrice",SqlDbType.Decimal)  
                                      , new SqlParameter("@TotalDiscountAmount",SqlDbType.Decimal)
                                      , new SqlParameter("@TotalRevenueAmount",SqlDbType.Decimal)};
            sqlParam[0].Value = _OOrderDetails.IDOrder;
            sqlParam[1].Value = _OOrderDetails.IDProduct;
            sqlParam[2].Value = _OOrderDetails.TotalQuantity;
            sqlParam[3].Value = _OOrderDetails.TotalPrice;
            sqlParam[4].Value = _OOrderDetails.TotalDiscountAmount;
            sqlParam[5].Value = _OOrderDetails.TotalRevenueAmount;
            if (RunProcedure("sp_tblOrderDetails_add", sqlParam))
            {
                return true;
            }
            return false;
        }
        public IList<OOrderDetails> Get(int IDOrder)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDOrder", SqlDbType.Int) };
            sqlParam[0].Value = IDOrder;
            return Common.Common.ConvertTo<OOrderDetails>(RunProcedureGet("sp_tblOrderDetails_get", sqlParam));
        }
        public bool Delete(int IDOrder,int IDProduct)
        {
            SqlParameter[] sqlParam = { new SqlParameter("@IDOrder", SqlDbType.Int),new SqlParameter("@IDProduct",SqlDbType.Int) };
            sqlParam[0].Value = IDOrder;
            sqlParam[1].Value = IDProduct;
            return RunProcedure("sp_tblOrderDetails_delete", sqlParam);
        }
    }
}
